package controller

import (
	"gin-demo/service"
	"gin-demo/tool"

	"github.com/gin-gonic/gin"
)

type FoodCategoryController struct {
}

func (fcc *FoodCategoryController) Router(e *gin.Engine) {
	e.GET("/api/food_category", fcc.foodCategory)
}

func (fcc *FoodCategoryController) foodCategory(c *gin.Context) {
	fcs := &service.FoodCategortyService{}
	categories, err := fcs.Category()
	if err != nil {
		tool.Failed(c, "数据获取失败")
		return
	}

	// 数据格式转换
	for _, category := range categories {
		if category.ImageUrl != "" {
			category.ImageUrl = tool.FileServerAddr() + "/" + category.ImageUrl
		}
	}
	tool.Success(c, categories)
}
